<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>

        function f() {
            //数据源
            let types = [
                {id: 1, name: 'x1'},
                {id: 2, name: 'x2'},
                {id: 3, name: 'x3'},
            ]
            let se = document.getElementById('se')
            //types.forEach 循环这个数组
            //types.forEach( 你想干点儿啥 )
            //v 每个对象
            types.forEach(function(v){
                //列表添加选项
                //new Option(显示文本 ,值)
                //se.options 所有选项的集合
                //add 添加一项
                se.options.add(new Option(v.name,v.id))
            })
        }

        window.onload = f;
    </script>

</head>

<body>
    <select id="se" onchange="console.log(this.value)">
        <option value="0">请选择</option>
    </select>
</body>
</html>

